package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.Question;
import cn.wolfcode.trip.base.domain.QuestionReply;
import cn.wolfcode.trip.base.mapper.QuestionMapper;
import cn.wolfcode.trip.base.mapper.QuestionReplyMapper;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.query.QuestionQueryObject;
import cn.wolfcode.trip.base.service.IQuestionReplyService;
import cn.wolfcode.trip.base.service.IQuestionService;
import cn.wolfcode.trip.base.util.UserContext;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class QuestionReplyServiceImpl implements IQuestionReplyService {
    @Autowired
    private QuestionReplyMapper questionReplyMapper;

    public void save(QuestionReply qo) {
        qo.setUser(UserContext.getUser());
        qo.setCreatTime(new Date());
        questionReplyMapper.insert(qo);
    }

    public PageInfo<Question> queryForQuestionReply(QuestionQueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(), qo.getPageSize());
        List<Question> list = questionReplyMapper.selectReplyByQuestionId(qo);
        return new PageInfo(list);
    }

}
